#include "StdAfx.h"
#include "SgPolygon.h"
#include <vector>
using namespace std;

CSgPolygon::CSgPolygon(void)
{
}

CSgPolygon::~CSgPolygon(void)
{
}

void CSgPolygon::Render(void)
{
	if(!m_Texture.Empty() )
	{
		 glEnable(GL_TEXTURE_2D);
		 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		 glBindTexture(GL_TEXTURE_2D, m_Texture.TexName());
	}

	glBegin(GL_POLYGON);
	// iterate through all vertices
    for(unsigned k = 0; k < m_vertices.size(); k++)
    {
		// added bounds checking and texture coordinates support

		if (m_normals.size() > (unsigned)k)
			glNormal3dv(m_normals[k]);

		if (m_tvertices.size() > (unsigned)k)
			glTexCoord2dv(m_tvertices[k]);

		glVertex3dv(m_vertices[k]);
    }
    glEnd();

	if( !m_Texture.Empty() )
		glDisable( GL_TEXTURE_2D );
}
